package com.yellow.routingservice.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yellow.routingservice.entity.Route;
import com.yellow.routingservice.mapper.RouteMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

/**
 * @author: hy
 * @create: 2024-04-14
 */
@Service
public class RouteServiceImpl extends ServiceImpl<RouteMapper, Route> implements RouteService {
    @Resource
    private RouteMapper routeMapper;

    @Override
    public Route findByOrderId(int orderId) {
        LambdaQueryWrapper<Route> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Route::getOrderId, orderId);
        return routeMapper.selectOne(wrapper);
    }

    @Override
    public Integer countRoutes() {
        return Math.toIntExact(routeMapper.selectCount(null));
    }
}
